<template>
	<view>
		<media-list v-if="list.length>0" type="one" v-for="(item,index) in list"
		:key="index" :item="item" :index="index"></media-list>
		<!-- 默认样式 -->
		<view v-if="list.length===0" class="flex w-100 align-center justify-center text-secondary" style="height: 100rpx;">
			暂无数据
		</view>
		<view v-if="list.length>=10" class="flex align-center justify-center py-3 bg-light">
			<text class="text-muted font">{{loadtext}}</text>
		</view>
	</view>
</template>

<script>
	import mediaList from '@/components/common/media-list.vue';
	export default {
		components: {
			mediaList
		},
		data() {
			return {
				list:[],
				loadtext:'上拉加载更多',
				category_id:0,
				page:1
			}
		},
		onLoad(options) {
			if(!options.id){
				return uni.navigateBack({
					delta:1
				})
			}
			this.category_id=options.id
			this.getData()
		},
		onPullDownRefresh() {
			this.page=1
			this.getData().then(res=>{
				uni.showToast({
					title:'刷新成功',
					icon:'none'
				})
				uni.stopPullDownRefresh()
			}).catch(err=>{
				uni.showToast({
					title:'刷新失败',
					icon:'none'
				})
				uni.stopPullDownRefresh()
			})
		},
		onReachBottom() {
			if(this.loadtext!=='上拉加载更多'){
				return
			}
			this.page+=1
			this.getData().catch(err=>{
				this.page-=1
				this.loadtext="上拉加载更多"
			})
		},
		methods: {
			getData(){
				this.loadtext='加载中...'
				return this.$H.get(`/category/${this.category_id}/video/${this.page}`).then(res=>{
					this.list=this.page===1?res:[...this.list,...res],
					this.loadtext=this.page*10===this.list.length?'上拉加载更多':'没有更多啦'
				})
			}
		}
	}
</script>

<style>

</style>
